// pages/vip/vip.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    vipList: []
  },

  selectedShowTap: function(e) { //显示&隐藏
    let that = this;
    let idx = e.currentTarget.dataset.idx;
    // console.log(idx)
    let { vipList } = that.data;
    vipList[idx].hidden = !vipList[idx].hidden;
    // console.log(vipList)
    that.setData({
      vipList
    })
  },

  goPeopleCardTap: function(e) { //进入名片
    app.confirmLogin(
      function() {
        let id = e.currentTarget.dataset.id;
        let userId =wx.getStorageSync('userId');
        if(id==userId){
          wx.navigateTo({
            url: '/pages/my-card/my-card?id=' + id,
          })
          return;
        }
        console.log(id)
        wx.navigateTo({
          url: '/pages/people-card/people-card?id=' + id,
        })
      })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getMemberList();
  },

  getMemberList: function() {
    var that = this;
    app.request(app.globalData.host + 'member/getMemberList', {}, 'GET', false,
      function(res) {
        wx.hideLoading();
        console.log(res)
        var vipList = res.data.data.list;
        (vipList || []).map((v, k) => v.hidden = false)
        that.setData({
          vipList: vipList,
          topimg: res.data.data.system.topuserimglogo
        })
      },
      function(err) {},
      function(complete) {})
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    wx.showLoading({
      title: '加载中',
    })
    this.data.vipList = [];
    this.data.topimg='';
    this.getMemberList();
    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})